home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / geometryPaint.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  26.2 KB  |  878 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. // Copyright (C) 1997-1998 Alias|Wavefront,
  19. // a division of Silicon Graphics Limited.
  20. //
  21. // The information in this file is provided for the exclusive use of the
  22. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  23. // and incorporate this code into other products for purposes authorized
  24. // by the Alias|Wavefront license agreement, without fee.
  25. //
  26. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  27. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  28. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  29. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  30. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  31. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  32. // PERFORMANCE OF THIS SOFTWARE.
  33. //
  34. //
  35. //  Alias|Wavefront Script File
  36. //  MODIFY THIS AT YOUR OWN RISK
  37. //
  38. //  Creation Date:  Oct 1997
  39. //
  40. //  Description:
  41. //     This is an example script for the Maya Artisan Script
  42. //     Paint tool. It will paint geometry onto the selected surfaces.
  43. //     Various aspects of the geometry are controlled by the painted
  44. //     values.
  45. //
  46. // Usage:
  47. // 1) Place this script into your scripts directory (usually the
  48. //    maya/scripts directory in your home directory
  49. // 2) Select the Script Paint Tool (Modify->Script Paint Tool)
  50. //    and bring up the Tool Settings window
  51. // 3) Go to the Setup tab and enter "geometryPaint" into the
  52. //    "Tool Setup Cmd" field and hit enter
  53. // 4) Paint Geometry
  54. //
  55. // Tips:
  56. // Once you have the Geometry Paint Tool setup you may want to drag
  57. // it from the minibar to the shelf so that it is always accessible
  58. //
  59. // These are global variables used to keep track of multiple
  60. // surfaces and the name prefixes used for the geometries on each
  61. // surface
  62. //
  63. global string $geometryNamePrefix[];
  64. global string $geometryParentName[];
  65. global string $geometryGroupName[];
  66. global int $geometryType[];        // 0 - NURBS surface, 1 - mesh
  67. global int $geometryPaintFreeSlot = 0;
  68. global int $geometryPaintSlots = 0;
  69.  
  70. global string $geometryGeom[];
  71. global string $geometryValidGeom[];
  72.  
  73. // determines which operation we are in:
  74. // 1 - create/modify, 2 - modify, 3 - remove
  75. //
  76. global int $geometryOperation = 1;
  77.  
  78. // These are global variables used to control what will happen
  79. // during painting. These globals are modified using a separate
  80. // UI window created when this tool becomes active.
  81. //
  82. global int $geometryUseGrid = 1;
  83. global int $geometryGridSizeU = 20;
  84. global string $geometryGridSizeUSlider;
  85. global int $geometryGridSizeV = 20;
  86. global string $geometryGridSizeVSlider;
  87. global int $geometryJitterGrid = 1;
  88. global float $geometryJitterValueAmt = 0.0;
  89. global int $geometryAttachToSrf = 1;
  90. global int $geometryAlignToSrf = 0;
  91. global int $geometryDuplicate = 1;
  92. global int $geometryGroup = 1;
  93. global int $geometryProportional = 0;
  94. global int $geometryIsolate = 1;
  95. global string $geometryAttrName[] = { ".sx", ".sy", ".sz", ".rx", ".ry", ".rz", ".tx", ".ty", ".tz" };
  96. global int $geometryModifyAttr[] = { 1, 1, 1, 0, 0, 0, 0, 0, 0 };
  97. global float $geometryModifyAttrNorm[] = { 1, 1, 1, 360, 360, 360, 1, 1, 1 };
  98. global int $geometryModifyAttrWrap[] = { 0, 0, 0, 1, 1, 1, 0, 0, 0 };
  99. global string $geometryIdentifier = "Geom";
  100. global string $geometryAlignChkBoxGrp;
  101.  
  102. proc chkRotateHelperPlugin()
  103. {
  104.     global int $geometryAlignToSrf;
  105.     global string $geometryAlignChkBoxGrp;
  106.  
  107.     if ( $geometryAlignToSrf && !`pluginInfo -q -loaded rotateHelper.so` ) {
  108.         if ( catch( `loadPlugin rotateHelper.so` ) ) {
  109.             warning( "couldn't load plugin (rotateHelper) required for Align option");
  110.             $geometryAlignToSrf = 0;
  111.  
  112.             // disable Align option
  113.             //
  114.             checkBoxGrp -e -en3 0 -v3 0 $geometryAlignChkBoxGrp;
  115.         }
  116.     }
  117. }
  118.  
  119. global proc geometryPaintAlignToSrfCB( int $align )
  120. {
  121.     global int $geometryAlignToSrf;
  122.     
  123.     $geometryAlignToSrf = $align;
  124.     chkRotateHelperPlugin;
  125. }
  126.  
  127. // This procedure creates the dialog box used to control various
  128. // parameters that control what happens when painting.
  129. // NOTE: This is in no way meant to be an example of good UI
  130. // design!
  131. //
  132. proc geometryPaintUI( string $context ) 
  133. {
  134.     global int $geometryOperation;
  135.     global int $geometryUseGrid;
  136.     global int $geometryGridSizeU;
  137.     global int $geometryGridSizeV;
  138.     global string $geometryGridSizeUSlider;
  139.     global string $geometryGridSizeVSlider;
  140.     global string $geometryAlignChkBoxGrp;
  141.     global int $geometryJitterGrid;
  142.     global int $geometryAttachToSrf;
  143.     global int $geometryAlignToSrf;
  144.     global int $geometryDuplicate;
  145.     global int $geometryGroup;
  146.     global int $geometryProportional;
  147.     global int $geometryIsolate;
  148.     global string $geometryGeom[];
  149.     global int $geometryModifyAttr[];
  150.     global float $geometryJitterValueAmt;
  151.     global string $geometryIdentifier;
  152.  
  153.     if ( `window -ex geometryPaintWindow` )
  154.     {
  155.         showWindow geometryPaintWindow ;
  156.         return ;
  157.     }
  158.     
  159.     setUITemplate -pushTemplate DefaultTemplate;
  160.     window -title "Geometry Paint Settings" geometryPaintWindow;
  161.     columnLayout -adj false -cal left
  162.         column;
  163.  
  164.             string $geom;
  165.             int $numGeoms = size($geometryGeom);
  166.             int $g;
  167.             for ( $g = 0; $g < $numGeoms; $g++ ) {
  168.                 $geom = ($geom + " " + $geometryGeom[$g]);
  169.             }
  170.             textFieldGrp -label "Geometry:"
  171.                          -text $geom
  172.                          -cc "tokenize( \"#1\", $geometryGeom )"
  173.                          geometryName; 
  174.             textFieldGrp -label "Identifier:"
  175.                          -text $geometryIdentifier
  176.                          -cc "$geometryIdentifier = \"#1\""
  177.                          geometryIdentifier; 
  178.             radioButtonGrp -l "Operation:" -nrb 3
  179.                 -l1 "Create/Modify"
  180.                 -on1 "$geometryOperation = 1"
  181.                 -l2 "Modify"
  182.                 -on2 "$geometryOperation = 2"
  183.                 -l3 "Remove"
  184.                 -on3 "$geometryOperation = 3"
  185.                 -sl $geometryOperation 
  186.                 operation;
  187.             checkBoxGrp -ncb 2 -l ""
  188.                         -l1 "Grid"
  189.                         -v1 $geometryUseGrid
  190.                         -cc1 "$geometryUseGrid = #1; intSliderGrp -e -en $geometryUseGrid $geometryGridSizeUSlider; intSliderGrp -e -en $geometryUseGrid $geometryGridSizeVSlider"
  191.                         -l2 "Jitter Grid"
  192.                         -v2 $geometryJitterGrid
  193.                         -cc2 "$geometryJitterGrid = #1"
  194.                         useGrid;
  195.             $geometryGridSizeUSlider=`
  196.                 intSliderGrp -field true -l "U Grid Size:" -min 2 -max 100
  197.                          -v $geometryGridSizeU
  198.                          -cc "$geometryGridSizeU = #1"
  199.                          -en $geometryUseGrid
  200.                          uGrid`; 
  201.             $geometryGridSizeVSlider=`
  202.                 intSliderGrp -field true -l "V Grid Size:" -min 2 -max 100
  203.                          -v $geometryGridSizeV
  204.                          -cc "$geometryGridSizeV = #1"
  205.                          -en $geometryUseGrid
  206.                          vGrid`;
  207.             checkBoxGrp -ncb 3 -l "Control:"
  208.                         -l1 "X Scale" -v1 $geometryModifyAttr[0]
  209.                         -cc1 "$geometryModifyAttr[0] = #1"
  210.                         -l2 "Y Scale" -v2 $geometryModifyAttr[1]
  211.                         -cc2 "$geometryModifyAttr[1] = #1"
  212.                         -l3 "Z Scale" -v3 $geometryModifyAttr[2]
  213.                         -cc3 "$geometryModifyAttr[2] = #1"
  214.                         control0;
  215.             checkBoxGrp -ncb 3 -l ""
  216.                         -l1 "X Rot" -v1 $geometryModifyAttr[3]
  217.                         -cc1 "$geometryModifyAttr[3] = #1"
  218.                         -l2 "Y Rot" -v2 $geometryModifyAttr[4]
  219.                         -cc2 "$geometryModifyAttr[4] = #1"
  220.                         -l3 "Z Rot" -v3 $geometryModifyAttr[5]
  221.                         -cc3 "$geometryModifyAttr[5] = #1"
  222.                         control1;
  223.             checkBoxGrp -ncb 3 -l ""
  224.                         -l1 "X Trans" -v1 $geometryModifyAttr[6]
  225.                         -cc1 "$geometryModifyAttr[6] = #1"
  226.                         -l2 "Y Trans" -v2 $geometryModifyAttr[7]
  227.                         -cc2 "$geometryModifyAttr[7] = #1"
  228.                         -l3 "Z Trans" -v3 $geometryModifyAttr[8]
  229.                         -cc3 "$geometryModifyAttr[8] = #1"
  230.                         control2;
  231.             checkBoxGrp -ncb 3 -l "Options:"
  232.                         -l1 "Proportional"
  233.                         -v1 $geometryProportional
  234.                         -cc1 "$geometryProportional = #1"
  235.                         -l2 "Attach"
  236.                         -v2 $geometryAttachToSrf
  237.                         -cc2 "$geometryAttachToSrf = #1"
  238.                         -l3 "Duplicate"
  239.                         -v3 $geometryDuplicate
  240.                         -cc3 "$geometryDuplicate = #1"
  241.                         options0;
  242.  
  243.             $geometryAlignChkBoxGrp = `
  244.                 checkBoxGrp -ncb 3 -l ""
  245.                         -l1 "Group"
  246.                         -v1 $geometryGroup
  247.                         -cc1 "$geometryGroup = #1"
  248.                         -l2 "Isolate"
  249.                         -v2 $geometryIsolate
  250.                         -cc2 "$geometryIsolate = #1"
  251.                         -l3 "Align"
  252.                         -v3 $geometryAlignToSrf
  253.                         -cc3 "geometryPaintAlignToSrfCB( #1 )"
  254.                         options1`;
  255.             floatSliderGrp -field true -l "Jitter Value:" -min 0 -max 1 -pre 2
  256.                          -v $geometryJitterValueAmt
  257.                          -cc "$geometryJitterValueAmt = #1"
  258.                          jitterRange;
  259.         setParent ..;
  260.     setParent ..;
  261.     showWindow geometryPaintWindow;
  262.     setUITemplate -popTemplate;
  263. }
  264.  
  265. // This procedure should be set as the "Tool Setup Cmd" in the 
  266. // Setup tab of the Maya Artisan Script Paint tool's tool
  267. // settings window. The tool context is supplied as an argument.
  268. //
  269. global proc geometryPaint( string $context )
  270. {
  271.     // initialize all the other commands in this scriptable 
  272.     // paint tool context.
  273.     // 
  274.     artUserPaintCtx -e
  275.         -ic "initGeometryPaint"
  276.         -fc "finishGeometryPaint"
  277.         -svc "setGeometryPaintValue"
  278.         -gvc "getGeometryPaintValue"
  279.         -gsc ""
  280.         -cc ""
  281.         -tcc "cleanupGeometryPaint"
  282.         -gac ""
  283.         $context;
  284.         
  285.     // create the dialog box to control various parameters
  286.     //
  287.     geometryPaintUI( $context );
  288.  
  289.     // We force the tool to use texture paint
  290.     // mode (as opposed to projection paint mode)
  291.     //
  292.     // userPaintCtx -e -painttype "forceTexture" $context;
  293. }
  294.  
  295. // This is the "Tool Cleanup Cmd". It is called when the tool is
  296. // exited. In this case, the special dialog window that was created
  297. // is deleted
  298. //
  299. global proc cleanupGeometryPaint( string $context )
  300. {
  301.     if ( `window -ex geometryPaintWindow` ) {
  302.         deleteUI geometryPaintWindow;
  303.     }
  304. }
  305.  
  306. global proc int checkForValidGeometry()
  307. {
  308.     global string $geometryGeom[];
  309.     global string $geometryValidGeom[];
  310.  
  311.     int $numGeom = size($geometryGeom);
  312.     int $g, $fg;
  313.  
  314.     clear($geometryValidGeom);
  315.     for( $g = 0, $fg = 0; $g < $numGeom; $g++ ) {
  316.         // check if geometry exists
  317.         //
  318.         if ( `objExists $geometryGeom[$g]` ) {
  319.             $geometryValidGeom[$fg] = $geometryGeom[$g];
  320.             $fg++;
  321.         }
  322.     }
  323.     return $fg;
  324. }
  325.  
  326. // This is the "Initialize Cmd". This procedure is called once
  327. // for every selected surface when an intial click is received
  328. // on any surface. The argument is the name of the surface. This
  329. // procedure returns a string which indicates to the scriptable
  330. // tool how to behave for the duration of the stroke. 
  331. //
  332. global proc string initGeometryPaint( string $name )
  333. {
  334.     global string $geometryNamePrefix[];
  335.     global string $geometryParentName[];
  336.     global string $geometryGroupName[];
  337.     global int $geometryType[];
  338.     global int $geometryPaintFreeSlot;
  339.     global int $geometryPaintSlots;
  340.     global int $geometryUseGrid;
  341.     global int $geometryGridSizeU;
  342.     global int $geometryGridSizeV;
  343.     global int $geometryJitterGrid;
  344.     global int $geometryGroup;
  345.     global int $geometryAttachToSrf;
  346.     global int $geometryAlignToSrf;
  347.     global int $geometryOperation;
  348.     global string $geometryIdentifier;
  349.  
  350.     if ( checkForValidGeometry() == 0 ) {
  351.         // return enough to make sure the set method gets
  352.         // called correctly
  353.         //
  354.         warning( "There is no valid geometry to paint" );
  355.         return "-uv surface -position local -normal world";
  356.     }
  357.  
  358.     // find a free slot for this surface in the global arrays
  359.     //
  360.     int $slot;
  361.  
  362.     for ( $slot = $geometryPaintFreeSlot; $slot < $geometryPaintSlots; $slot++ ) {
  363.         if ( $geometryNamePrefix[$slot] == "" ) {
  364.             break;
  365.         }
  366.     }  
  367.  
  368.     if ( $slot == $geometryPaintSlots ) {
  369.         $geometryPaintSlots++;
  370.         $geometryPaintFreeSlot = $geometryPaintSlots;
  371.     }
  372.  
  373.     int        $paintableObject = 1;
  374.  
  375.     if ( `nodeType $name` == "nurbsSurface" ) {
  376.         $geometryType[$slot] = 0;
  377.     } else if ( `nodeType $name` == "mesh" ) {
  378.         $geometryType[$slot] = 1;
  379.     } else {
  380.         $paintableObject = 0;
  381.     }
  382.  
  383.     if ( $paintableObject ) {
  384.         // save the name of the parent of this shape as well
  385.         // as a prefix to use when creating the geometrys and
  386.         // and a group name if $geometryGroup is true
  387.         //
  388.         string $parent[] = `listRelatives -p $name`;
  389.         $geometryParentName[$slot] = $parent[0];
  390.         $geometryNamePrefix[$slot] = $parent[0] + $geometryIdentifier;
  391.         $geometryGroupName[$slot] = $parent[0] + $geometryIdentifier + "Grp";
  392.  
  393.         if ( $geometryOperation == 1 && $geometryGroup && ! `objExists $geometryGroupName[$slot]` ) {
  394.             // Make a group for the painted geometries. Place it at the
  395.             // same level as the surface
  396.             //
  397.             string $parentParent[] = `listRelatives -p $geometryParentName[$slot]`;
  398.  
  399.             if ( size($parentParent) > 0 ) {
  400.                 group -em -p $parentParent[0] -n $geometryGroupName[$slot];
  401.             } else {
  402.                 group -em -w -n $geometryGroupName[$slot];
  403.             }
  404.  
  405.             // Connect this new transform to the surface's transform
  406.             //
  407.             string $from = $geometryParentName[$slot];
  408.             string $to = $geometryGroupName[$slot];
  409.             string $attr[] = { "t", "r", "ro", "s", "sh",
  410.                                "rp", "rpt", "sp", "spt" };
  411.  
  412.             for ( $a = 0; $a < size($attr); $a++ ) {
  413.                 connectAttr ($from + "." + $attr[$a]) ($to + "." + $attr[$a]);
  414.             }
  415.         }
  416.  
  417.         if ( $geometryAlignToSrf ) {
  418.             // check if we have rotateHelper plugin
  419.             // - this may change $geometryAlignToSrf flag
  420.             //
  421.             chkRotateHelperPlugin;
  422.  
  423.             // if geometry alignment is desired but geometry attachment isn't, create
  424.             // some dependency nodes to help out with this and create the constant
  425.             // connections
  426.             // - at the current time only NURBS surfaces can be attached to
  427.             //
  428.             if ( $geometryAlignToSrf
  429.               && ( ! $geometryAttachToSrf || $geometryType[$slot] != 0 ) ) {
  430.                 int $created = 0;
  431.     
  432.                 if ( ! `objExists geometryPaintPOSNode` ) {
  433.                     createNode pointOnSurfaceInfo -name geometryPaintPOSNode;
  434.                     $created = 1;
  435.                 }
  436.                 if ( ! `objExists geometryPaintBRNode` ) {
  437.                     createNode rotateHelper -name geometryPaintBRNode;
  438.                     $created = 1;
  439.                 }
  440.                 if ( ! `objExists geometryPaintMeshBRNode` ) {
  441.                     createNode rotateHelper -name geometryPaintMeshBRNode;
  442.                     $created = 1;
  443.                 }
  444.                 if ( $created ) {
  445.                     connectAttr geometryPaintPOSNode.normal geometryPaintBRNode.up;
  446.                     connectAttr geometryPaintPOSNode.tangentU geometryPaintBRNode.forward;
  447.                 }
  448.             }
  449.         }
  450.     }
  451.  
  452.     // Return an argument string which:
  453.     // - tells the tool what surface ID to use for this surface
  454.     // - indicate that the associated surface parameter location
  455.     //   should also be passed to the "Set Value Cmd".
  456.     //
  457.     string $jitter;
  458.     string $position;
  459.     string $grid;
  460.  
  461.     if ( $geometryJitterGrid ) {
  462.         $jitter = "true";
  463.     } else { 
  464.         $jitter = "false";
  465.     }
  466.     if ( $geometryGroup ) {
  467.         $position = "local";
  468.     } else { 
  469.         $position = "world";
  470.     }
  471.     if ( $geometryUseGrid ) {
  472.         $grid = (" -grid " + $geometryGridSizeU  + " " + $geometryGridSizeV);
  473.     } else {
  474.         $grid = "";
  475.     }
  476.     return ( "-id " + $slot
  477.            + $grid
  478.            + " -jitter " + $jitter
  479.            + " -uv surface"
  480.            + " -position " + $position
  481.            + " -normal " + $position );
  482. }
  483.  
  484. // This is the "Finalize Cmd". This procedure is called at the
  485. // end of the stroke. It is passed the surface ID, that was
  486. // generated by the "Initialize Cmd".
  487. //
  488. global proc finishGeometryPaint( int $slot )
  489. {
  490.     global string $geometryNamePrefix[];
  491.     global int $geometryPaintFreeSlot;
  492.  
  493.     // clear out the slot that was used for this surface
  494.     //
  495.     if ( $slot >= 0 ) {
  496.         $geometryNamePrefix[$slot] = "";
  497.         if ( $slot < $geometryPaintFreeSlot ) {
  498.             $geometryPaintFreeSlot = $slot;
  499.         }
  500.     }
  501. }
  502.  
  503. proc string getRandomGeometry()
  504. {
  505.     global string $geometryValidGeom[];
  506.  
  507.     int $index = trunc( rand( size($geometryValidGeom) - 0.5 ) );
  508.     return $geometryValidGeom[$index];
  509. }
  510.  
  511. proc setGeometryAttributes(
  512.     string $objname,
  513.     float $val
  514. )
  515. {
  516.     global int $geometryModifyAttr[];
  517.     global float $geometryModifyAttrNorm[];
  518.     global string $geometryAttrName[];
  519.     global int $geometryModifyAttrWrap[];
  520.     global int $geometryProportional;
  521.     global float $geometryJitterValueAmt;
  522.  
  523.     int $attr;
  524.     int $numAttr = size($geometryModifyAttr);
  525.     float $normVal;
  526.  
  527.     if ( $geometryJitterValueAmt > 0 ) {
  528.         float $jitterRange = abs( $val ) * $geometryJitterValueAmt;
  529.  
  530.         $val = rand( $val - $jitterRange, $val + $jitterRange );
  531.     }
  532.  
  533.     if ( $geometryProportional ) {
  534.         float $proportions[];
  535.         float $total;
  536.         float $curVal;
  537.  
  538.         // proportionally split the passed in value across all
  539.         // modifiable attributes 
  540.         //
  541.  
  542.         // find the proportions of all modifiable attributes
  543.         //
  544.         for ( $attr = 0; $attr < $numAttr; $attr++ ) {
  545.             if ( $geometryModifyAttr[$attr] ) {
  546.                 $curVal = `getAttr ($objname + $geometryAttrName[$attr])`;
  547.                 
  548.                 if ( $geometryModifyAttrNorm[$attr] != 1 ) {
  549.                     $curVal /= $geometryModifyAttrNorm[$attr];
  550.                 }
  551.                 if ( $geometryModifyAttrWrap[$attr] ) {
  552.                     $curVal = fmod( $curVal, 1.0 );
  553.                 }
  554.                 $proportions[$attr] = $curVal;
  555.                 $total += abs( $curVal );
  556.             }
  557.         }
  558.  
  559.         // go through them all again and split the passed in
  560.         // value proportionately
  561.         //
  562.         for ( $attr = 0; $attr < $numAttr; $attr++ ) {
  563.             if ( $geometryModifyAttr[$attr] ) {
  564.                 if ( $total > 0 ) {
  565.                     $normVal = $val * $proportions[$attr] / $total;
  566.                 } else {
  567.                     $normVal = $val;
  568.                 }
  569.  
  570.                 if ( $geometryModifyAttrNorm[$attr] != 1 ) {
  571.                     $normVal = $normVal * $geometryModifyAttrNorm[$attr];
  572.                 }
  573.  
  574.                 // print ($objname + $geometryAttrName[$attr] + " set to " + $normVal + "\n");
  575.                 setAttr ($objname + $geometryAttrName[$attr]) $normVal;
  576.             }
  577.         }
  578.     } else {
  579.         // replace all modifiable attributes with normalized value
  580.         //
  581.         for ( $attr = 0; $attr < $numAttr; $attr++ ) {
  582.             if ( $geometryModifyAttr[$attr] ) {
  583.                 if ( $geometryModifyAttrNorm[$attr] != 1 ) {
  584.                     $normVal = $val * $geometryModifyAttrNorm[$attr];
  585.                 } else {
  586.                     $normVal = $val;
  587.                 }
  588.  
  589.                 // print ($objname + $geometryAttrName[$attr] + " set to " + $normVal + "\n");
  590.                 setAttr ($objname + $geometryAttrName[$attr]) $normVal;
  591.             }
  592.         }
  593.     }
  594. }
  595.  
  596. // This is the "Set Value Cmd". It is called everytime a value
  597. // on the surface is changed. A surface ID, a grid index
  598. // on the surface and the value associated with that grid index
  599. // is passed. There can be additional arguments depending on the
  600. // options generated by the return value of the "Initialize Cmd".
  601. // In this case the (u,v) surface parameter position for this
  602. // grid point as well as its local position is passed.
  603. // 
  604. global proc setGeometryPaintValue(
  605.     int $slot,
  606.     int $index,
  607.     float $val,
  608.     float $u,
  609.     float $v,
  610.     float $x,
  611.     float $y,
  612.     float $z,
  613.     float $nx,
  614.     float $ny,
  615.     float $nz
  616. )
  617. {
  618.     global string $geometryNamePrefix[];
  619.     global string $geometryParentName[];
  620.     global string $geometryGroupName[];
  621.     global int $geometryType[];
  622.     global int $geometryAttachToSrf;
  623.     global int $geometryAlignToSrf;
  624.     global int $geometryDuplicate;
  625.     global int $geometryGroup;
  626.     global int $geometryOperation;
  627.     global int $geometryIsolate;
  628.  
  629.     if ( $slot < 0 ) {
  630.         return;
  631.     }
  632.  
  633.     if ( $geometryNamePrefix[$slot] != "" ) {
  634.         // determine the name of the geometry associated with this
  635.         // grid location as well as the name of the
  636.         // pointOnSurfaceInfo node that attaches the geometry to
  637.         // the surface
  638.         //
  639.         string $objname = $geometryNamePrefix[$slot] + $index;
  640.         string $srfpoint = ($objname + "Loc");
  641.         string $alignGeom = ($objname + "Align");
  642.         string $posname = ($objname + "Pos");
  643.  
  644.         if ( `objExists $objname` ) {
  645.             // the geometry already exists
  646.             //
  647.             if ( $geometryOperation == 3 ) {
  648.                 // we are removing geometry; only remove if val > 0
  649.                 //
  650.                 if ( $val > 0 ) {
  651.                     if ( `objExists $posname` ) {
  652.                         delete $posname;
  653.                     } else {
  654.                         delete $objname;
  655.                     }
  656.                     if ( `objExists $srfpoint` ) {
  657.                         delete $srfpoint;
  658.                     }
  659.                     if ( `objExists $alignGeom` ) {
  660.                         delete $alignGeom;
  661.                     }
  662.  
  663.                     // if there is a group and it's empty delete it
  664.                     //
  665.                     if ( `objExists $geometryGroupName[$slot]` ) {
  666.                         string $children[] = `listRelatives -c $geometryGroupName[$slot]`;
  667.  
  668.                         if ( size($children) == 0 ) {
  669.                             delete $geometryGroupName[$slot];
  670.                         }
  671.                     }
  672.                 }
  673.             } else {
  674.                 // modify geometry attributes
  675.                 //
  676.                 setGeometryAttributes( $objname, $val );
  677.             }
  678.         } else if ( $val > 0 && $geometryOperation == 1 ) {
  679.             // the geometry doesn't exist
  680.             //
  681.             string $sname[];
  682.             string $geom = getRandomGeometry();
  683.  
  684.             // create a geometry with the proper name, scale it by
  685.             // the passed value
  686.             //
  687.             if ( $geometryDuplicate ) {
  688.                 $sname=`duplicate -n $objname $geom`;
  689.             } else {
  690.                 $sname=`instance -n $objname $geom`;
  691.             }
  692.             if ( $sname[0] != $objname ) {
  693.                 error ("Geometry name failed: wanted " + $objname + " got " + $sname[0]);
  694.                 return;
  695.             }
  696.             showHidden $objname;
  697.  
  698.             if ( $geometryIsolate ) {
  699.                 group -n $posname $objname;
  700.  
  701.                 // make sure the rotate and scale pivots and
  702.                 // translations are the same in $posname as
  703.                 // they are in $objname
  704.                 //
  705.                 float $p[3];
  706.                 
  707.                 $p = `xform -q -os -rp $objname`;
  708.                 xform -p false -os -rp $p[0] $p[1] $p[2];
  709.                 $p = `xform -q -os -rt $objname`;
  710.                 xform -p false -os -rt $p[0] $p[1] $p[2];
  711.                 $p = `xform -q -os -sp $objname`;
  712.                 xform -p false -os -sp $p[0] $p[1] $p[2];
  713.                 $p = `xform -q -os -st $objname`;
  714.                 xform -p false -os -st $p[0] $p[1] $p[2];
  715.             } else {
  716.                 $posname = $objname;
  717.             }
  718.             if ( $geometryGroup ) {
  719.                 parent -r $posname $geometryGroupName[$slot];
  720.             }
  721.             setGeometryAttributes( $objname, $val );
  722.  
  723.             string $outSrfAttr;
  724.  
  725.             if ( $geometryGroup ) {
  726.                 $outSrfAttr = ".local";
  727.             } else {
  728.                 $outSrfAttr = ".worldSpace";
  729.             }
  730.  
  731.             // attach only works on NURBS surfaces right now
  732.             //
  733.             if ( $geometryAttachToSrf && $geometryType[$slot] == 0 ) {
  734.                 // create point on surface node which will be used to
  735.                 // attach the geometry to the surface
  736.                 //
  737.                 createNode pointOnSurfaceInfo -n $srfpoint;
  738.                 setAttr ($srfpoint + ".u") $u;
  739.                 setAttr ($srfpoint + ".v") $v;
  740.                 connectAttr ($geometryParentName[$slot] + $outSrfAttr) ($srfpoint + ".is");
  741.                 connectAttr ($srfpoint + ".position") ($posname + ".translate");
  742.  
  743.                 if ( $geometryAlignToSrf ) {
  744.                     createNode rotateHelper -n $alignGeom;
  745.  
  746.                     connectAttr ($srfpoint + ".normal") ($alignGeom + ".up");
  747.                     connectAttr ($srfpoint + ".tangentU") ($alignGeom + ".forward");
  748.                     connectAttr ($alignGeom + ".rotate") ($posname + ".rotate");                
  749.                 }
  750.             } else {
  751.                 if ( $geometryGroup ) {
  752.                     move -ls $x $y $z $posname;
  753.                 } else {
  754.                     move -ws $x $y $z $posname;
  755.                 }
  756.  
  757.                 if ( $geometryAlignToSrf ) {
  758.                     string    $helperNode;
  759.                     string    $outSrf;
  760.  
  761.                     switch ( $geometryType[$slot] ) {
  762.                     case 0:    // NURBS surface
  763.                         // use global nodes to calculate required rotation
  764.                         //
  765.                         $outSrf = ($geometryParentName[$slot] + $outSrfAttr);
  766.                         connectAttr $outSrf geometryPaintPOSNode.is;
  767.                         setAttr geometryPaintPOSNode.u $u;
  768.                         setAttr geometryPaintPOSNode.v $v;
  769.                         $helperNode = "geometryPaintBRNode";
  770.                         break;
  771.                     case 1:    // poly mesh
  772.                         setAttr geometryPaintMeshBRNode.upX $nx;
  773.                         setAttr geometryPaintMeshBRNode.upY $ny;
  774.                         setAttr geometryPaintMeshBRNode.upZ $nz;
  775.                         $helperNode = "geometryPaintMeshBRNode";
  776.                         break;
  777.                     }
  778.  
  779.  
  780.                     // set rotation of object 
  781.                     // - rotateHelper plugin has a bug where it doesn't recompute
  782.                     //   unless asked for rotate attribute
  783.                     //
  784.                     getAttr ($helperNode + ".rotate");
  785.                     rotate `getAttr ($helperNode + ".rx")`
  786.                            `getAttr ($helperNode + ".ry")`
  787.                            `getAttr ($helperNode + ".rz")` $posname;
  788.  
  789.                     switch ( $geometryType[$slot] ) {
  790.                     case 0:    // NURBS surface
  791.                         // disconnect the surface
  792.                         //
  793.                         disconnectAttr $outSrf geometryPaintPOSNode.is;
  794.                         break;
  795.                     case 1:    // poly mesh
  796.                         break;
  797.                     }
  798.                 }
  799.             }
  800.         }
  801.     }
  802. }
  803.  
  804. // This is the "Get Value Cmd". It is called everytime a value
  805. // on the surface is needed by the scriptable paint tool. A
  806. // surface ID and a grid index is passed in. This procedure should
  807. // return the value for this grid location on the specified surface.
  808. // 
  809. global proc float getGeometryPaintValue( int $slot, int $index )
  810. {
  811.     global string $geometryNamePrefix[];
  812.     global int $geometryModifyAttr[];
  813.     global int $geometryModifyAttrWrap[];
  814.     global float $geometryModifyAttrNorm[];
  815.     global string $geometryAttrName[];
  816.     global int $geometryOperation;
  817.     global int $geometryProportional;
  818.  
  819.     if ( $slot >= 0 && $geometryNamePrefix[$slot] != "" ) {
  820.         // if this slot is valid, generate the name for the
  821.         // geometry at this grid index
  822.         //
  823.         string $objname = $geometryNamePrefix[$slot] + $index;
  824.  
  825.         if ( `objExists $objname` ) {
  826.             if ( $geometryOperation == 3 ) {
  827.                 // we are removing geometry
  828.                 //
  829.                 return 0.0;
  830.             } else {
  831.                 float $total = 0;
  832.                 int $num = 0;
  833.                 int $attr;
  834.                 int $numAttr = size($geometryModifyAttr);
  835.                 float $val;
  836.     
  837.                 // get the sum of normalized attributes
  838.                 //
  839.                 for ( $attr = 0; $attr < $numAttr; $attr++ ) {
  840.                     if ( $geometryModifyAttr[$attr] ) {
  841.                         $val = `getAttr ($objname + $geometryAttrName[$attr])`;
  842.                         
  843.                         // print ("getAttr " + $objname + $geometryAttrName[$attr] + " = " + $val);
  844.                         if ( $geometryModifyAttrNorm[$attr] != 1 ) {
  845.                             $val /= $geometryModifyAttrNorm[$attr];
  846.                         }
  847.                         if ( $geometryModifyAttrWrap[$attr] ) {
  848.                             $val = fmod( $val, 1.0 );
  849.                         }
  850.                         // print (" normalized = " + $val + "\n");
  851.                         if ( $geometryProportional ) {
  852.                             $val = abs( $val );
  853.                         }
  854.                         $total += $val;
  855.                         $num++;
  856.                     }
  857.                 }
  858.                 if ( $num > 0 ) {
  859.                     if ( $geometryProportional ) {
  860.                         return $total;
  861.                     } else {
  862.                         return $total / $num;
  863.                     }
  864.                 } else {
  865.                     return 0.0;
  866.                 }
  867.             }
  868.         } else {
  869.             // the geometry doesn't exist, therefore return 0 as
  870.             // the value for this grid location
  871.             //
  872.             return 0.0;
  873.         }
  874.     } else {
  875.         return 0.0;
  876.     }
  877. }
  878.